#include <stdio.h>  
#include <string.h>  
char decor[2][3];  
char num[2][3];  
int score[2][3];  
  
int decorValue(char dc) {  
    switch (dc) {  
        case 'H':  
            return 80;  
        case 'S':  
            return 60;  
        case 'D':  
            return 40;  
        case 'C':  
            return 20;  
        default:  
            return 100;  
    }  
}  
  
int numValue(char num) {  
    if (num <= '9' && num >= '2')  
        return num - '0';  
    switch (num) {  
        case '\0':  
            return 10;  
        case 'J':  
            return 11;  
        case 'Q':  
            return 12;  
        case 'K':  
            return 13;  
        case 'A':  
            return 14;  
        default:  
            return 100;  
    }  
}  
  
void swapC(char *c, int i, int j) {  
    char temp = *(c + i);  
    *(c + i) = *(c + j);  
    *(c + j) = temp;  
}  
  
void swap(int *c, int i, int j) {  
    int temp = *(c + i);  
    *(c + i) = *(c + j);  
    *(c + j) = temp;  
}  
  
void output(void) {  
    for (int i = 0; i < 2; i++) {  
        printf("%c:", 'A' + i);  
        for (int j = 0; j < 3; j++) {  
            if (num[i][j] == '\0')  
                printf("%2c10", decor[i][j]);  
            else  
                printf("%2c%c", decor[i][j], num[i][j]);  
        }  
        putchar('\n');  
    }  
  
}  
  
int main() {  
    for (int i = 0; i < 2; i++)  
        for (int j = 0; j < 3; j++)  
            if (scanf("%c%c", &decor[i][j], &num[i][j])) {  
                char x = getchar();  
                if (num[i][j] == '1' && x == '0') {  
                    num[i][j] = '\0';  
                    getchar();  
                }  
                if (decorValue(decor[i][j]) == 100 || numValue(num[i][j]) == 100) {  
                    printf("Input Error!\n");  
                    return 0;  
                }  
                score[i][j] = decorValue(decor[i][j]) + numValue(num[i][j]);  
            }  
    for (int i = 0; i < 3; i++)  
        for (int j = i + 1; j < 3; j++)  
            if (score[0][j] > score[0][i]) {  
                swap(score, i, j);  
                swapC(decor, i, j);  
                swapC(num, i, j);  
            }  
    for (int i = 0; i < 3; i++)  
        for (int j = i + 1; j < 3; j++)  
            if (score[1][j] > score[1][i]) {  
                swap(score + 1, i, j);  
                swapC(decor + 1, i, j);  
                swapC(num + 1, i, j);  
            }  
    for (int i = 0; i < 2; i++)  
        if (score[i][0] == score[i][1] || score[i][0] == score[i][2] ||  
                score[i][2] == score[i][1]) {  
            printf("Input Error!\n");  
            return 0;  
        }  
    for (int i = 0; i < 3; i++) {  
        if (score[0][i] > score[1][i]) {  
            printf("Winner is A!\n");  
            output();  
            return 0;  
        } else if (score[0][i] < score[1][i]) {  
            printf("Winner is B!\n");  
            output();  
            return 0;  
        }  
    }  
    printf("Winner is X!\n");  
    output();  
    return 0;  
}  